package com.rxjava;

import com.rxjava.bean.User;
import com.rxjava.http.UserHttp;
import com.rxjava.http.UserModel;

import rx.Subscriber;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by kkmike999 on 16/3/21.
 */
public class RxjavaHttpMain {

    public static void main(String[] args) throws InterruptedException {
        new UserModel().loadUser()
                .subscribeOn(Schedulers.io())

                .observeOn(Schedulers.computation())
                .doOnNext(new Action1<User>() {
                    @Override
                    public void call(User user) {
                        System.out.println(Thread.currentThread());
                        System.out.println("doOnNext\n");
                    }
                })

                .observeOn(Schedulers.newThread())
                .subscribe(new Subscriber<User>() {
                    public void onCompleted() {
                        System.out.println("onCompleted");
                    }

                    public void onError(Throwable throwable) {
                        System.out.println(throwable.getMessage());
                    }

                    public void onNext(User user) {
                        System.out.println(Thread.currentThread());
                        System.out.println(user);
                    }
                });

        Thread.sleep(2000);
    }
}
